/*
 * Copyright (C) 2011 xjuraj
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package sk.lieskove.jianghongtiao.websearch.document.preprocessing;

/**
 *
 * @author xjuraj
 */
public enum SupportedLanguages {

    
    Afrikaans("af", "afr", "afr"),
    Albanian("sq", "alb", "sqi"),
    Arabic("ar", "ara", "ara"),
    Bengali("bn", "ben", "ben"),
    Bulgarian("bg", "bul", "bul"),
    Castilian("es", "spa", "spa"),
    Chinese("zh", "chi", "zho"),
    Croatian("hr", "hrv", "hrv"),
    Czech("cs", "cze", "ces"),
    Danish("da", "dan", "dan"),
    Dutch("nl", "dut", "nld"),
    English("en", "eng", "eng"),
    Estonian("et", "est", "est"),
    Finnish("fi", "fin", "fin"),
    Flemish("nl", "dut", "nld"),
    French("fr", "fre", "fra"),
    German("de", "ger", "deu"),
    Greek_Modern("el", "gre", "ell"),
    Gujarati("gu", "guj", "guj"),
    Hebrew("he", "heb", "heb"),
    Hindi("hi", "hin", "hin"),
    Hungarian("hu", "hun", "hun"),
    Indonesian("id", "ind", "ind"),
    Italian("it", "ita", "ita"),
    Japanese("ja", "jpn", "jpn"),
    Kannada("kn", "kan", "kan"),
    Korean("ko", "kor", "kor"),
    Latvian("lv", "lav", "lav"),
    Lithuanian("lt", "lit", "lit"),
    Macedonian("mk", "mac", "mkd"),
    Malayalam("ml", "mal", "mal"),
    Marathi("mr", "mar", "mar"),
    Moldavian("ro", "rum", "ron"),
    Moldovan("ro", "rum", "ron"),
    Nepali("ne", "nep", "nep"),
    Northern_Sami("se", "sme", "sme"),
    Norwegian("no", "nor", "nor"),
    Panjabi("pa", "pan", "pan"),
    Persian("fa", "per", "fas"),
    Polish("pl", "pol", "pol"),
    Portuguese("pt", "por", "por"),
    Punjabi("pa", "pan", "pan"),
    Romanian("ro", "rum", "ron"),
    Russian("ru", "rus", "rus"),
    Slovak("sk", "slo", "slk"),
    Slovenian("sl", "slv", "slv"),
    Somali("so", "som", "som"),
    Spanish("es", "spa", "spa"),
    Swahili("sw", "swa", "swa"),
    Swedish("sv", "swe", "swe"),
    Tagalog("tl", "tgl", "tgl"),
    Tamil("ta", "tam", "tam"),
    Telugu("te", "tel", "tel"),
    Thai("th", "tha", "tha"),
    Turkish("tr", "tur", "tur"),
    Ukrainian("uk", "ukr", "ukr"),
    Urdu("ur", "urd", "urd"),
    Vietnamese("vi", "vie", "vie"),
    SimplifiedChinese("zh", "chi", "zho"),
    TraditionalChinese("zh", "chi", "zho");
    
    private final String iso639_1;
    private final String iso639_2_B;
    private final String iso639_2_T;

    private SupportedLanguages(String iso639_1, String iso639_2_B, String iso639_2_T) {
        this.iso639_1 = iso639_1;
        this.iso639_2_B = iso639_2_B;
        this.iso639_2_T = iso639_2_T;
    }

    public SupportedLanguages fromIso369_1(String v) {
        //also in containsValue method
        if(v.equals("zh-cn")) return SupportedLanguages.SimplifiedChinese;
        if(v.equals("zh-tw")) return SupportedLanguages.TraditionalChinese;
        for (SupportedLanguages c : SupportedLanguages.values()) {
            if (c.iso639_1.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException("Value '" + v
                + "' is not correct value for type " + SupportedLanguages.class.getName());
    }

    public SupportedLanguages fromIso369_2_B(String v) {
        for (SupportedLanguages c : SupportedLanguages.values()) {
            if (c.iso639_2_B.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException("Value '" + v
                + "' is not correct value for type " + SupportedLanguages.class.getName());
    }

    public SupportedLanguages fromIso369_2_T(String v) {
        for (SupportedLanguages c : SupportedLanguages.values()) {
            if (c.iso639_2_T.equals(v)) {
                return c;
            }
        }
        throw new IllegalArgumentException("Value '" + v
                + "' is not correct value for type " + SupportedLanguages.class.getName());
    }

    public String toIso369_1() {
        return iso639_1;
    }

    public String toIso369_2_B() {
        return iso639_2_B;
    }

    public String toIso369_2_T() {
        return iso639_2_T;
    }
    
    public boolean containsValue(String v) {
        //also in fromIso369_1 method
        if(v.equals("zh-cn")) return true;
        if(v.equals("zh-tw")) return true;
        for (SupportedLanguages c : SupportedLanguages.values()) {
            if (c.iso639_1.equals(v) || c.iso639_2_B.equals(v) || c.iso639_2_T.equals(v)) {
                return true;
            }
        }
        return false;
    }
}
